<div class="BorderBox">
                  <img src='icons/22/mail-mark-task.png'> <?php ELang("task"); ?>
                  <?php
                  if ($_SESSION['userlevel'] >= LEVEL_CREATE_TASK) {
                     printf("<a class='tooltip' href='edit_task.php?id=-1'><img src='icons/22/list-add.png'><div class='rtooltiptext'>%s</div></a>", RLang("createtask"));
                  }
                  ?>
                  <div class="SubList">


                     <?php
                     if ($_SESSION['userlevel'] >= LEVEL_UNRETIRE_TASK)
                        $sql = "SELECT name, id, project_id, retired FROM task order by project_id";
                     else
                        $sql = "SELECT name, id, project_id, retired FROM task where retired is null order by project_id";

                     if (!$result = get_db_result($db, $sql, null)) {
                        echo ($sql . " ");
                        die(mysqli_error($db));
                     }



                     # Interating through all task works only if they are ordered by project_id
                     $currentProject = null;
                     $rowcnt = mysqli_num_rows($result);
                     $lastindex = $rowcnt - 1;
                     for ($i = 0; $i < $rowcnt; $i++) {
                        $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
                        $id = $row['id'];
                        $name = $row['name'];
                        $pid = $row['project_id'];
                        # currentProject is not null and not like $cid means => close current div and start new one
                        if ($currentProject != null && $currentProject != $pid) {
                           echo ("</table>\r\n");
                           $currentProject = null;
                        }
                        # currentProject is null means first element => just new div open
                        if ($currentProject == null) {

                           echo ("<table class=\"DataTable TaskGroup\" id='tg" . $pid . "' width=\"100%\"" . ($pid == $lastProject ? "" : "style=\"display:none\"") . ">\r\n\t\t");
                           echo ("<col width='22'>\r\n\t\t");
                           echo ("<col width='auto'>\r\n\t\t");
                           echo ("<col width='22'>\r\n\t\t");
                           echo ("<col width='22'>\r\n\t\t");
                           $currentProject = $pid;
                        }
                        echo ("<tr>\r\n\t\t\t");
                        echo ("<td>\r\n\t\t\t\t<a href='maintime.php?task_filter=$id'><img src='icons/22/view-filter.png'></a>\r\n\t\t\t</td>\r\n\t\t\t");
                        echo ("<td>\r\n\t\t\t\t");
                        if ($lastTask == $id || ($lastTask == 0 && $i == 0))
                           echo ("<input type=\"radio\" id=\"t$id\" onclick=\"selectTask($id)\" name=\"task\" class=\"Task\" value=\"$id\" checked=\"checked\">");
                        else
                           echo ("<input type=\"radio\" id=\"t$id\" onclick=\"selectTask($id)\" name=\"task\" class=\"Task\" value=\"$id\">");
                        echo ($name . "\r\n\t\t\t");
                        echo ("</td>");
                        if ($row['retired'] == null) {
                           if ($_SESSION['userlevel'] >= LEVEL_RETIRE_TASK)
                              printf("\r\n\t\t\t<td>\r\n\t\t\t\t<a class='tooltip' href='retire_task.php?id=%s'><img src='icons/22/list-remove.png'>
                              <div class='ltooltiptext'>%s</div></a>\r\n\t\t\t</td>\r\n\t\t\t", $id, RLang("retiretask"));
                           if ($_SESSION['userlevel'] >= LEVEL_EDIT_TASK)
                              printf("<td>\r\n\t\t\t\t<a class='tooltip' href='edit_task.php?id=%s'><img src='icons/22/document-edit.png'>
                              <div class='ltooltiptext'>%s</div></a>\r\n\t\t\t</td>", $id, RLang("edittask"));
                        } else if ($_SESSION['userlevel'] >= LEVEL_UNRETIRE_TASK) {
                           printf("<td>\r\n\t\t\t\t<a class='tooltip' href='unretire_task.php?id=%s'><img src='icons/22/view-refresh.png'>
                           <div class='ltooltiptext'>%s</div></a>\r\n\t\t\t</td>", $id, RLang("unretiretask"));
                        }
                        echo ("\r\n\t\t</tr>\r\n\t");
                        #if last element (index check) close current div
                        if ($i == $lastindex) {
                           echo ("</table>\r\n");
                        }
                     }
                     mysqli_free_result($result);
                     ?>

                  </div>
               </div>

               <div class="BorderBox">
                  <img src='icons/22/resource-group.png'> <?php ELang("customer"); ?>
                  <?php
                  if ($_SESSION['userlevel'] >= LEVEL_CREATE_CUSTOMER) {
                     printf("<a class='tooltip' href='edit_customer.php?id=-1'><img src='icons/22/list-add.png'><div class='rtooltiptext'>%s</div></a>\r\n", RLang("createcustomer"));
                  }
                  ?>
                  <div class="SubList">
                     <table class="DataTable" width="100%">
                        <col width="auto">
                        <col width="22">
                        <col width="22">

                        <?php
                        if ($_SESSION['userlevel'] >= LEVEL_UNRETIRE_CUSTOMER)
                           $sql = "SELECT c.id as cid, c.name as cname, c.retired FROM customer c order by c.id";
                        else
                           $sql = "SELECT c.id as cid, c.name as cname, c.retired FROM customer c where c.retired is null order by c.id";
                        if (!$result = get_db_result($db, $sql, null)) {
                           echo ($sql . " ");
                           die(mysqli_error($db));
                        }


                        $rowcnt = mysqli_num_rows($result);
                        for ($i = 0; $i < $rowcnt; $i++) {
                           $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
                           $id = $row['cid'];
                           echo ("<tr>\r\n\t<td>\r\n\t\t");
                           if ($lastcustomer == $id || ($lastcustomer == 0 && $i == 0))
                              echo ("<input type=\"radio\" id=\"c$id\" onClick=\"selectCustomer($id)\" name=\"customer\" class=\"Customer\" value=\"$id\" checked=\"checked\">\r\n");
                           else
                              echo ("<input type=\"radio\" id=\"c$id\" onClick=\"selectCustomer($id)\" name=\"customer\" class=\"Customer\" value=\"$id\">\r\n");
                           echo ($row['cname']);
                           echo ("</td>\r\n\t");

                           if ($row['retired'] == null) {
                              if ($_SESSION['userlevel'] >= LEVEL_RETIRE_CUSTOMER)
                                 printf("<td>\r\n\t\t<a class='tooltip' href='retire_customer.php?id=%s'><img src='icons/22/list-remove.png'><div class='ltooltiptext'>%s</div></a>\r\n\t</td>\r\n\t", $id, RLang("retirecustomer"));
                              if ($_SESSION['userlevel'] >= LEVEL_EDIT_CUSTOMER)
                                 printf("<td>\r\n\t\t<a class='tooltip' href='edit_customer.php?id=%s'><img src='icons/22/document-edit.png'><div class='ltooltiptext'>%s</div></a>\r\n\t</td>\r\n\t", $id, RLang("editcustomer"));
                           } else if ($_SESSION['userlevel'] >= LEVEL_UNRETIRE_CUSTOMER) {
                              printf("<td>\r\n\t\t<a class='tooltip' href='unretire_customer.php?id=%s'><img src='icons/22/view-refresh.png'><div class='ltooltiptext'>%s</div></a>\r\n\t</td>\r\n\t", $id, RLang("unretirecustomer"));
                           }

                           echo ("</tr>\r\n");
                        }
                        mysqli_free_result($result);
                        ?>
                     </table>
                  </div>
               </div>